package com.example.frameboot.common;


import lombok.Builder;
import lombok.Data;

@Data
@Builder
public class BusinessException extends RuntimeException {

    private int code;

    private String message;


    public static void check(boolean condition, HttpStatusEnum statusEnum) {
        if (condition) {
            throwException(statusEnum);
        }
    }

    public static void check(boolean condition, HttpStatusEnum statusEnum, String addtionalMessage) {
        if (condition) {
            throwException(statusEnum, addtionalMessage);
        }
    }

    public static void throwException(HttpStatusEnum statusEnum) {
        throw BusinessException
                .builder()
                .code(statusEnum.getCode())
                .message(statusEnum.getMessage())
                .build();
    }

    public static void throwException(HttpStatusEnum statusEnum, String addtionalMessage) {
        throw BusinessException
                .builder()
                .code(statusEnum.getCode())
                .message(statusEnum.getMessage() + "：" + addtionalMessage)
                .build();
    }

    public static void throwException(int code, String message) {
        throw BusinessException
                .builder()
                .code(code)
                .message(message)
                .build();
    }
}
